package org.hang.gift.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import org.hang.gift.domain.Employee;
import org.hang.gift.mapper.EmployeeMapper;
import org.hang.gift.query.EmployeeQuery;
import org.hang.gift.service.IEmployeeService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.hang.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hang
 * @since 2024-03-22
 */
@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements IEmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public PageList<Employee> PageQuery(EmployeeQuery query) {
        //封装分页对象，即分页的条件:当前页是第几页，一页有几条数据
        Page<Employee> page = new Page<>(query.getPage(),query.getRows());

        //获取查询的结果（当前页的所有数据）
        List<Employee> employees = employeeMapper.PageQuery(page, query.getKeyword());

        //将查询结果封装成我们自己的分页对象（数据总条数，当前页要显示的数据）
        PageList<Employee> pageList = new PageList<>(page.getTotal(), employees);
        return pageList;
    }
}
